package com.yulian.web_api.report;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;

import com.yulian.repository.CommonRepositoryImpl;
import com.yulian.util.CommonUtils;
import com.yulian.util.XLSX2CSV;

import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.Log4JLoggerFactory;
import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.pgclient.PgPool;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import io.vertx.sqlclient.Tuple;

//导入商品内部赔偿单明细细
public class HandleGoodIndoorSubsidyDetail {

    final InternalLogger logger = Log4JLoggerFactory.getInstance(HandleGoodIndoorSubsidyDetail.class);
    CommonRepositoryImpl commonRepository = new CommonRepositoryImpl();

    public Future<JsonObject> handleExcelFile(Vertx vertx, PgPool pool, JsonObject config, String file_name) {
        // 最后返回给客户端的 json 对象
        Promise<JsonObject> promise = Promise.promise();
        JsonObject responseJSObj = new JsonObject();
        responseJSObj.put("msg", "处理Excel文件结果:");

        this.commonRepository.getCon(pool)
        .onSuccess(conn -> {
            /*** 处理上传的excel
             * 利用OPCPackage 打开文件
             */
            int minColumns = -1;
            BufferedReader bReader;
            //2. read data from excel
            try (OPCPackage p = OPCPackage.open(file_name, PackageAccess.READ)) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                PrintStream out = new PrintStream(baos);
                //read the excel to csv
                XLSX2CSV xlsx2csv = new XLSX2CSV(p, out, minColumns);
                xlsx2csv.process();
                ByteArrayInputStream in = new ByteArrayInputStream(baos.toByteArray());
                bReader = new BufferedReader(new InputStreamReader(in));

                String line = "";
                //忽略前三行
                for (int i = 0; i < 3; i++) {
                    line = bReader.readLine();
                }
                //统计记录总数
                int count = 0;
                boolean item_not_null_valid = true;
                List<String> errMsgList = new ArrayList<String>();
                List<Tuple> good_indoor_subsidy_detail_batch = new ArrayList<>();

                @SuppressWarnings("rawtypes")
                List<Future> futures = new ArrayList<Future>();
                while ((line = bReader.readLine()) != null) {
                    item_not_null_valid = true;
                    if (line.trim() != "") {
                        count = count + 1;
                        String[] data = line.split(":");
                        // 获取各个字段的值

                        String site_name = "";
                        if (!data[0].toString().equals("")) {
                            site_name = data[0].toString();
                            //0校验销售地区的合法性
                            String get_id_sql = "select distinct id from  site where site_name = $1 and is_delete=0";
                            Future<JsonObject> checkSiteNameFuture = this.commonRepository.getIdByNameFuture2(conn, get_id_sql, site_name, "销售地区", count, "good_indoor_subsidy_detail_check_site_name");
                            futures.add(checkSiteNameFuture);
                        } else {
                            errMsgList.add("第" + count + "行的销售地区为空");
                            item_not_null_valid = false;
                        }
                        String warehouse_name = "";
                        if (!data[1].toString().equals("")) {
                            warehouse_name = data[1].toString();
                            //1校验仓库名的合法性
                            String get_id_sql = "select distinct id from  warehouse where warehouse_name = $1 and is_delete=0";
                            Future<JsonObject> checkWarehouseNameFuture = this.commonRepository.getIdByNameFuture2(conn, get_id_sql, warehouse_name, "仓库名", count, "good_indoor_subsidy_detail_check_warehouse_name");
                            futures.add(checkWarehouseNameFuture);
                        } else {
                            errMsgList.add("第" + count + "行的仓库名为空");
                            item_not_null_valid = false;
                        }

                        String good_indoor_subsidy_code = "";
                        if (!data[2].toString().equals("")) {
                            good_indoor_subsidy_code = data[2].toString();
                            //2校验商品内部赔偿单编号是否为空
                        } else {
                            errMsgList.add("第" + count + "行的商品内部赔偿单编号为空");
                            item_not_null_valid = false;
                        }

                        String generate_date = "";
                        if (!data[3].toString().equals("")) {
                            generate_date = data[3].toString();
                            //3校验生成日是否为空
                        } else {
                            errMsgList.add("第" + count + "行的生成日为空");
                            item_not_null_valid = false;
                        }
                        //聚合商品id
                        String aggregation_name = "";
                        if (!data[4].toString().equals("")) {
                            aggregation_name = data[4].toString();
                            //4校验聚合商品的合法性
                            String get_id_sql = "select distinct id from aggregation_goods where aggregation_name = $1 and is_delete=0";
                            Future<JsonObject> checkAggregationNameFuture = this.commonRepository.getIdByNameFuture2(conn, get_id_sql, aggregation_name, "聚合商品", count, "good_indoor_subsidy_detail_check_aggregation_name");
                            futures.add(checkAggregationNameFuture);
                        } else {
                            errMsgList.add("第" + count + "行的聚合商品为空");
                            item_not_null_valid = false;
                        }
                        //供应链商品名
                        String supply_chain_goods_name = "";
                        if (!data[5].toString().equals("")) {
                            supply_chain_goods_name = data[5].toString();
                            //5校验供应链商品名的合法性
                            String get_id_sql = "select distinct id from supply_chain_goods where supply_chain_goods_name = $1 and is_delete=0";
                            Future<JsonObject> checkSupplyChainGoodsNameFuture = this.commonRepository.getIdByNameFuture2(conn, get_id_sql,
                            supply_chain_goods_name, "供应链商品名", count, "good_indoor_subsidy_detail_check_supply_chain_goods_name");
                            futures.add(checkSupplyChainGoodsNameFuture);
                        } else {
                            errMsgList.add("第" + count + "行的供应链商品名为空");
                            item_not_null_valid = false;
                        }

                        //商品批次号
                        String goods_batch_code = "";
                        if (!data[6].toString().equals("") && this.commonRepository.isNumericA(data[6].toString())) {
                            goods_batch_code = data[6].toString();
                            //6校验商品批次号的合法性(是否为数字)
                        } else {
                            errMsgList.add("第" + count + "行的商品批次号为空");
                            item_not_null_valid = false;
                        }
                        //实际供应链商品等级
                        String real_supply_chain_goods_grade_name = "";
                        if (!data[7].toString().equals("")) {
                            real_supply_chain_goods_grade_name = data[7].toString();
                            //7校验实际供应链商品等级的合法性
                            String get_id_sql = "select distinct id from goods_grade where grade_name = $1 and is_delete=0";
                            Future<JsonObject> checkRealSupplyChainGoodsGradeNameFuture = this.commonRepository.getIdByNameFuture2(conn, get_id_sql,
                            real_supply_chain_goods_grade_name, "实际供应链商品等级", count, "good_indoor_subsidy_detail_check_real_supply_chain_goods_grade_name");
                            futures.add(checkRealSupplyChainGoodsGradeNameFuture);
                        } else {
                            errMsgList.add("第" + count + "行的实际供应链商品等级为空");
                            item_not_null_valid = false;
                        }
                        //实际供应链商品结算包规
                        double real_supply_chain_goods_settle_package_spec = 0.00;
                        if (!data[8].toString().equals("") && this.commonRepository.isNumericA(data[8].toString())) {
                            real_supply_chain_goods_settle_package_spec = Double.parseDouble(data[8].toString());
                            //8校验实际供应链商品结算包规的合法性(是否为数字)
                        } else {
                            errMsgList.add("第" + count + "行的实际供应链商品结算包规为空");
                            item_not_null_valid = false;
                        }
                        //内部赔偿商品件数
                        double indoor_subsidy_number = 0.00;
                        if (!data[9].toString().equals("") && this.commonRepository.isNumericA(data[9].toString())) {
                            indoor_subsidy_number = Double.parseDouble(data[9].toString());
                            //9校验内部赔偿商品件数的合法性(是否为数字)
                        } else {
                            errMsgList.add("第" + count + "行的内部赔偿商品件数为空");
                            item_not_null_valid = false;
                        }
                        //内部赔偿商品重量
                        double indoor_subsidy_weight = 0.00;
                        if (!data[10].toString().equals("") && this.commonRepository.isNumericA(data[10].toString())) {
                            indoor_subsidy_weight = Double.parseDouble(data[10].toString());
                            //10校验内部赔偿商品重量的合法性(是否为数字)
                        } else {
                            errMsgList.add("第" + count + "行的内部赔偿商品重量为空");
                            item_not_null_valid = false;
                        }

                        //内部赔偿金额
                        double indoor_subsidy_price = 0.00;
                        if (!data[11].toString().equals("") && this.commonRepository.isNumericA(data[11].toString())) {
                            indoor_subsidy_price = Double.parseDouble(data[11].toString());
                            //11校验内部赔偿金额的合法性(是否为数字)
                        } else {
                            errMsgList.add("第" + count + "行的内部赔偿金额为空");
                            item_not_null_valid = false;
                        }
                        //到岸斤价
                        double land_price = 0.00;
                        if (!data[12].toString().equals("") && this.commonRepository.isNumericA(data[12].toString())) {
                            land_price = Double.parseDouble(data[12].toString());
                            //12校验到岸斤价的合法性(是否为数字)
                        } else {
                            errMsgList.add("第" + count + "行的到岸斤价为空");
                            item_not_null_valid = false;
                        }

                        //通过非空校验,将该行数据暂存入good_indoor_subsidy_detail_batch
                        if (item_not_null_valid) {
                            good_indoor_subsidy_detail_batch.add(Tuple.of(site_name, warehouse_name, good_indoor_subsidy_code, generate_date, aggregation_name, supply_chain_goods_name, goods_batch_code,
                            real_supply_chain_goods_grade_name, real_supply_chain_goods_settle_package_spec, indoor_subsidy_number, indoor_subsidy_weight, indoor_subsidy_price, land_price));
                        } else {
                            //若某一行数据非空检测结果不合法
                            responseJSObj.put("code",-1).put("msg", responseJSObj.getString("msg") + errMsgList.toString());
                            //跳出循环
                            break;
                        }
                    } //end if (line.trim() != "") {  //读取一行数据结束
                } //end while((line = bReader.readLine()) != null){  //所有数据读取完毕
                //数据读取完毕后，关闭bReader
                if (bReader != null) {
                    bReader.close();
                }
                // 关闭OPCPackage
                p.close();

                /***************  读取数据完毕，通过数据非空校验 ******/
                if (item_not_null_valid) {
                    logger.info("通过非空校验,继续执行值校验, future个数: {}", futures.size());
                    //继续执行数据合法校验
                    CompositeFuture.join(futures).onComplete(ar2 -> {
                        if (ar2.succeeded()) {
                            JsonObject check_result = new JsonObject();
                            boolean check_value_valid = true;
                            //需要知道每一个future对应的第几行第几列，从而准确取出相应的字段的编码
                            int tmp_row_num = 0;
                            String[] row_result = new String[5];
                            String method = "insert";
                            List<Tuple> insert_data_batch = new ArrayList<>();
                            for (int i = 0; i < futures.size(); i++) {//从1开始是因为第一个是获取总表最新id
                                check_result = (JsonObject) ar2.result().list().get(i);
                                //确定行数,从0开始 i = 1-9: row_num=0;  i = 10-18: row_num=1;
                                int row_num = i / 5;
                                //确定列数，从0开始
                                int col_num = i % 5;
                                if (row_num <= tmp_row_num) {
                                    if (check_result.getInteger("id") == -1) { //没有通过值校验
                                        check_value_valid = false;
                                        responseJSObj.put("code",-1).put("msg", responseJSObj.getString("msg") + "; " + check_result.getString("msg"));
                                        promise.complete(responseJSObj);
                                    } else {
                                        //通过校验,取出code存放在数组里
                                        row_result[col_num] = check_result.getString("data");
                                    }
                                    //当前项为一行的最后一列
                                    if (i == (tmp_row_num + 1) * 5 - 1) {
                                        // 处理当前一行数据;还原为一行一行数据进行处理
                                        Tuple tempTuple = good_indoor_subsidy_detail_batch.get(tmp_row_num);
                                        if (method.equals("insert")) {
                                            long v1 = Long.parseLong(row_result[0]);
                                            long v2 = Long.parseLong(row_result[1]);
                                            long v3 = Long.parseLong(row_result[2]);
                                            long v4 = Long.parseLong(row_result[3]);
                                            long v5 = Long.parseLong(row_result[4]);
                                            LocalDate localDate = LocalDate.parse(tempTuple.getString(3), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                                            insert_data_batch.add(Tuple.of(v1,v2, tempTuple.getString(2),
                                                    localDate,v3,v4,
                                            tempTuple.getString(6), v5,
                                                    tempTuple.getDouble(8),
                                                    tempTuple.getDouble(9),
                                                    tempTuple.getDouble(10),
                                            tempTuple.getDouble(11),
                                                    tempTuple.getDouble(12)));
                                        }
                                    }
                                } else {
                                    tmp_row_num = row_num;
                                    row_result = new String[5];
                                    //检查新的一行第一列的校验结果并存入row_result里
                                    if (check_result.getInteger("id") == -1) { //没有通过值校验
                                        check_value_valid = false;
                                        responseJSObj.put("code",-1).put("msg", responseJSObj.getString("msg") + "; " + check_result.getString("msg"));
                                        promise.complete(responseJSObj);
                                    } else { //通过校验
                                        row_result[col_num] = check_result.getString("data");
                                    }
                                }
                            }

                            /********** 通过全部数据合法性校验，准备进行写入或更新 *****/
                            if (check_value_valid) {
                                logger.info("通过全部值校验，准备进行写入或更新");
                                @SuppressWarnings("rawtypes")
                                //所有数据通过校验,执行insert or update 写入或更新数据
                                List<Future> futures2 = new ArrayList<Future>();
                                //所有数据通过校验,执行insert or update 写入或更新数据
                                String warehouse_ids="";
                                String supply_chain_goods_ids="";
                                String supply_chain_goods_settle_package_specs="";
                                String goods_batch_codes="";
                                //插入之前先判断有没有存在的存在则执行更新sql
                                for(int i =0 ; i< insert_data_batch.size();i++){
                                    if (i==insert_data_batch.size()-1){
                                        warehouse_ids=warehouse_ids+insert_data_batch.get(i).getLong(1);
                                        supply_chain_goods_ids=supply_chain_goods_ids+insert_data_batch.get(i).getLong(5);
                                        supply_chain_goods_settle_package_specs=supply_chain_goods_settle_package_specs+insert_data_batch.get(i).getDouble(8);
                                        goods_batch_codes=goods_batch_codes+"'"+insert_data_batch.get(i).getString(6)+"'";
                                    }else {
                                        warehouse_ids=warehouse_ids+insert_data_batch.get(i).getLong(1)+",";
                                        supply_chain_goods_ids=supply_chain_goods_ids+insert_data_batch.get(i).getLong(5)+",";
                                        supply_chain_goods_settle_package_specs=supply_chain_goods_settle_package_specs+insert_data_batch.get(i).getDouble(8)+",";
                                        goods_batch_codes=goods_batch_codes+"'"+insert_data_batch.get(i).getString(6)+"',";
                                    }
                                }
                                String select_sql="select warehouse_id,supply_chain_goods_id,real_supply_chain_goods_settle_package_spec,goods_batch_code " +
                                        "from good_indoor_subsidy_detail " +
                                        "where is_delete=0 " +
                                        "and warehouse_id in ("+warehouse_ids+") " +
                                        "and supply_chain_goods_id in ("+supply_chain_goods_ids+") "+
                                        "and real_supply_chain_goods_settle_package_spec in ("+supply_chain_goods_settle_package_specs+") "+
                                        "and goods_batch_code in ("+goods_batch_codes+") ";
                                this.commonRepository.queryJsonArray(conn, select_sql, "getGoodIndoorSubsidyDetailRecords")
                                        .onSuccess(resJSArray -> { //resJSArray中就是获取到符合条件的数据
                                            //所有数据通过校验,执行insert or update 写入或更新数据
                                            List<Tuple> new_insert_data_batch = new ArrayList<Tuple>();
                                            List<Tuple> update_data_batch = new ArrayList<Tuple>();
                                            if(resJSArray.size()>0){
                                                //有需要更新的数据
                                                for (int r = 0 ; r<insert_data_batch.size();r++){
                                                    boolean f= false;
                                                    Integer a = Math.toIntExact(insert_data_batch.get(r).getLong(1));
                                                    Integer a1 = Math.toIntExact(insert_data_batch.get(r).getLong(5));
                                                    BigDecimal bigDecimal2 =new BigDecimal(insert_data_batch.get(r).getDouble(8));
                                                    String str = insert_data_batch.get(r).getString(6);
                                                    for (int i = 0; i < resJSArray.size(); i++) {
                                                        JsonObject jsonObj = resJSArray.getJsonObject(i);
                                                        Integer warehouse_id = Integer.valueOf(jsonObj.getString("warehouse_id"));
                                                        Integer supply_chain_goods_id = Integer.valueOf(jsonObj.getString("supply_chain_goods_id"));
                                                        double real_supply_chain_goods_settle_package_spec = Double.parseDouble(jsonObj.getString("real_supply_chain_goods_settle_package_spec"));
                                                        String goods_batch_code= jsonObj.getString("goods_batch_code");
                                                        if (a==warehouse_id && a1==supply_chain_goods_id){
                                                            //相等则是需要更新的数据
                                                            BigDecimal bigDecimal1 =new BigDecimal(real_supply_chain_goods_settle_package_spec);
                                                            if (bigDecimal1.compareTo(bigDecimal2)==0  && goods_batch_code.equals(str)){
                                                                update_data_batch.add(Tuple.of(insert_data_batch.get(r).getLong(0),
                                                                        insert_data_batch.get(r).getString(2),
                                                                        insert_data_batch.get(r).getLocalDate(3),
                                                                        insert_data_batch.get(r).getLong(4),
                                                                        insert_data_batch.get(r).getLong(7),
                                                                        insert_data_batch.get(r).getDouble(9),
                                                                        insert_data_batch.get(r).getDouble(10),
                                                                        insert_data_batch.get(r).getDouble(11),
                                                                        insert_data_batch.get(r).getDouble(12),
                                                                        insert_data_batch.get(r).getLong(1),
                                                                        insert_data_batch.get(r).getLong(5),
                                                                        insert_data_batch.get(r).getDouble(8),
                                                                        insert_data_batch.get(r).getString(6)));
                                                                f=true;
                                                                break;
                                                            }
                                                        }
                                                    }
                                                    if (!f){
                                                        new_insert_data_batch.add(insert_data_batch.get(r));
                                                    }
                                                }
                                            }else {
                                                //没有需要更新的数据则是全部是新增
                                                for (int y = 0 ;y<insert_data_batch.size();y++){
                                                    new_insert_data_batch.add(insert_data_batch.get(y));
                                                }
                                            }
                                            if (new_insert_data_batch.size() > 0) {
                                                String insert_sql = "INSERT INTO good_indoor_subsidy_detail(site_id,warehouse_id, good_indoor_subsidy_code,generate_date, aggregation_id, supply_chain_goods_id," +
                                                        " goods_batch_code, real_supply_chain_goods_grade_id, real_supply_chain_goods_settle_package_spec,indoor_subsidy_number," +
                                                        "indoor_subsidy_weight,indoor_subsidy_price,land_price) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING id";

                                                Future<RowSet<Row>> insertGoodIndoorSubsidyDetailBatchFuture = this.commonRepository.insertOrUpdateBatch(conn, insert_sql, new_insert_data_batch, "insert_good_indoor_subsidy_detail_batch");
                                                futures2.add(insertGoodIndoorSubsidyDetailBatchFuture);
                                                logger.info("insert_data_batch size: {}", new_insert_data_batch.size());
                                            }
                                            if (update_data_batch.size()>0){
                                                String update_sql="update good_indoor_subsidy_detail set site_id=$1,good_indoor_subsidy_code=$2, " +
                                                        "  generate_date=$3,aggregation_id=$4,real_supply_chain_goods_grade_id=$5,indoor_subsidy_number=$6,indoor_subsidy_weight=$7, " +
                                                        "  indoor_subsidy_price=$8, land_price=$9 " +
                                                        " where warehouse_id=$10 and supply_chain_goods_id=$11 and real_supply_chain_goods_settle_package_spec=$12 and goods_batch_code=$13  ";
                                                Future<RowSet<Row>> updateInitialBatchDetialBatchFuture = this.commonRepository.insertOrUpdateBatch(conn, update_sql, update_data_batch, "update_good_damage_supplier_subsidy_detail_batch");
                                                futures2.add(updateInitialBatchDetialBatchFuture);
                                                logger.info("update_data_batch size: {}", update_data_batch.size());
                                            }
                                            if (futures2.size() > 0) {
                                                logger.info("futures2.size(): {}", futures2.size());
                                                CompositeFuture.join(futures2).onComplete(ar4 -> {
                                                    if (ar4.succeeded()) {
                                                        JsonObject insert_or_update_result = new JsonObject();
                                                        logger.info("insert_or_update_result: {}", insert_or_update_result.getString("msg"));
                                                        responseJSObj.put("code",200).put("msg", responseJSObj.getString("msg") + "; " + insert_or_update_result.getString("msg"));
                                                    } else {
                                                        responseJSObj.put("code",-1).put("msg", responseJSObj.getString("msg") + "; " + ar4.cause().getMessage());
                                                    }

                                                    //继续删除文件
                                                    vertx.fileSystem().delete(file_name, res0 -> {
                                                        if (res0.succeeded()) {
                                                            logger.info("读取excel后删除文件 {} 成功", file_name);
                                                            responseJSObj.put("code", 200).put("msg", responseJSObj.getString("msg") + "; 删除文件成功; 处理供应商信息完毕");
                                                        } else {
                                                            logger.info("读取excel后删除文件 {} 失败 ", file_name);
                                                            responseJSObj.put("code", 200).put("msg", responseJSObj.getString("msg") + "; 删除文件失败; 处理供应商信息完毕");
                                                        }
                                                        promise.complete(responseJSObj);
                                                    });
                                                });
                                            } else {
                                                //继续删除文件
                                                vertx.fileSystem().delete(file_name, res0 -> {
                                                    if (res0.succeeded()) {
                                                        logger.info("读取excel后删除文件 {} 成功", file_name);
                                                        responseJSObj.put("code", 200).put("msg", responseJSObj.getString("msg") + "; 删除文件成功; 处理供应商信息完毕");
                                                    } else {
                                                        logger.info("读取excel后删除文件 {} 失败 ", file_name);
                                                        responseJSObj.put("code", 200).put("msg", responseJSObj.getString("msg") + "; 删除文件失败; 处理供应商信息完毕");
                                                    }
                                                    promise.complete(responseJSObj);
                                                });
                                            }

                                        }).onFailure(err -> promise.complete(CommonUtils.createExceptionJsonObject(err, "getGoodIndoorSubsidyDetailRecords", "获取商品内部赔偿单明细失败")));
                            } else {
                                //部分数据校验没有通过，全部不写入数据；返回提示信息
                                //继续删除文件
                                vertx.fileSystem().delete(file_name, res0 -> {
                                    if (res0.succeeded()) {
                                        logger.info("读取excel后删除文件 {} 成功", file_name);
                                        responseJSObj.put("code", 200).put("msg", responseJSObj.getString("msg") + "; 删除文件成功; 处理供应商信息完毕");
                                    } else {
                                        logger.info("读取excel后删除文件 {} 失败 ", file_name);
                                        responseJSObj.put("code", 200).put("msg", responseJSObj.getString("msg") + "; 删除文件失败; 处理供应商信息完毕");
                                    }
                                    promise.complete(responseJSObj);
                                });
                            }

                        } else {
                            promise.fail(CommonUtils.createExceptionJsonObjectStr(ar2, "batchImportSupplierInfo", "执行数据合法性校验发生错误"));
                        }
                    });
                } else { //没有通过数据字段非空校验
//                    responseJSObj.put("code", -1).put("msg", "没有通过非空校验");
                    promise.complete(responseJSObj);
                }
            } catch (Exception err) {  //end try ( OPCPackage p = OPCPackage.open(file_name, PackageAccess.READ)) {
                promise.fail(CommonUtils.createExceptionJsonObjectStr(err, "handleExcelFile in batchImportSupplierInfo", "打开excel文件报错"));
            }
        }).onFailure(err -> promise.fail(CommonUtils.createExceptionJsonObjectStr(err, "batchImportSupplierInfo", "数据库连接失败")));
        return promise.future();
    }

}
